package com.yunchang.open.iploaction;

import com.yunchang.open.iploaction.utils.LocationUtil;

/**
 * IP的归属地区。
 * Created by jasontujun on 2019/6/24.
 */
public class Location {

    public static final String UNKNOWN = "unknown";

    /***
     * 国家
     */
    private String country;
    /***
     * 省份
     */
    private String province;
    /***
     * 城市
     */
    private String city;
    /**
     * 互联网服务供应商
     */
    private String isp;

    public Location() {
    }

    public Location(String country, String province, String city) {
        this(country, province, city, null);
    }

    public Location(String country, String province, String city, String isp) {
        setCountry(country);
        setProvince(province);
        setCity(city);
        setIsp(isp);
    }

    public String getCountry() {
        return country == null || country.length() == 0 ? UNKNOWN : country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getProvince() {
        return province == null || province.length() == 0 ? UNKNOWN : province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city == null || city.length() == 0 ? UNKNOWN : city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getIsp() {
        return isp == null || isp.length() == 0 ? UNKNOWN : isp;
    }

    public void setIsp(String isp) {
        this.isp = isp;
    }

    public boolean isUnknown() {
        return LocationUtil.isUnknownPlace(country) && LocationUtil.isUnknownPlace(province) && LocationUtil.isUnknownPlace(city);
    }

    public String toProvinceString() {
        return this.getCountry() + " " + this.getProvince();
    }

    @Override
    public String toString() {
        return this.getCountry() + " " + this.getProvince() + " " + this.getCity();
    }

}
